package temp;

//import net.whitbeck.rdbparser.*;
//import rdb.RDBParser;

import datastruct.list.impl.JoListII;
import datastruct.list.inter.IListConsumer;
import datastruct.sortedset.Element;
import jodis.conn.impl.IntReply;
import jodis.conn.impl.StatusReply;
import rdb.CRC;
import rdb.RDBConstant;

import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.IntBuffer;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.atomic.AtomicInteger;

public class Temp {

    private static JoListII myList = JoListII.makeListII();

    public static void increase() {
        for (int i = 0;i<10;i++) {
            System.out.printf("%s - %d\n", Thread.currentThread().getName(), i);
            myList.add("A");
        }
    }

    public static void main(String[] args) throws InterruptedException {
//        BitSet bitSet = new BitSet(5);
//        bitSet.set(40, true);
//        System.out.println(bitSet.get(40));
        LinkedList<Integer> ls = new LinkedList<>();
        for (int i = 0;i<10;i++) {
            ls.addLast(i+1);
        }

        ListIterator<Integer> iterator = ls.listIterator(2);
        iterator.next();
        iterator.add(11);
        for (Integer e : ls) {
            System.out.printf("%d ", e);
        }
        System.out.println();
//        Thread[] threads = new Thread[16];
//        for (int i = 0; i < 16; i++) {
//            System.out.printf("启动线程 %d\n", i);
//            threads[i] = new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    increase();
//                }
//            });
//            threads[i].start();
//        }
//        Thread.sleep(10000);
//        System.out.println(myList.Len());
//        LinkedList<Integer> deque = new LinkedList<>();
//        for (int i=1;i<7;i++) {
//            deque.add(i);
//        }
//
//        ListIterator<Integer> iterator = deque.listIterator(deque.size());
//        System.out.println(iterator.hasNext());
//        System.out.println(iterator.hasPrevious());
//
//        if (iterator.hasNext()) {
//            System.out.println("has next");
//            while (iterator.hasNext()) {
//                System.out.printf("%d, ", iterator.next());
//            }
//            System.out.println();
//        } else if (iterator.hasPrevious()) {
//            System.out.println("has previous");
//            while (iterator.hasPrevious()) {
//                System.out.printf("%d, ", iterator.previous());
//            }
//            System.out.println();
//        }


//        byte[] bs = {-1};
//        int res = ByteBuffer.wrap(bs).order(ByteOrder.nativeOrder()).getInt();
//        System.out.printf("%x\n", res);
//        try {
//            int preLen = 100;
//            BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("binary.bin"));
//            int code = 123456;
//            String s = new String(bs);
//            System.out.println(s);
//            byte[] bs = new byte[4];
//            for (int i=0;i<4;i++) {
//                bs[i] = (byte) (preLen >> (i*8));
//            }
//            out.write(Integer.toString(code).getBytes(StandardCharsets.UTF_8));
//            out.flush();
//            out.close();

//            BufferedReader jodisReader = new BufferedReader(new FileReader("jodis_result.txt"));
//            BufferedReader redisReader = new BufferedReader(new FileReader("redis_result.txt"));
//            String line1 = null, line2 = null;
//            while ((line1 = jodisReader.readLine()) != null && (line2 = redisReader.readLine()) != null ) {
//                String[] jodisItems = line1.split(":");
//                String[] redisItems = line2.split(":");
//
//                jodisItems[1] = jodisItems[1].trim();
//                redisItems[1] = redisItems[1].trim();
//
//                BigDecimal jodisQps = new BigDecimal(jodisItems[1]);
//                BigDecimal redisQps = new BigDecimal(redisItems[1]);
//
//                double diff = jodisQps.subtract(redisQps).doubleValue();
//
//                System.out.printf("%s: %s, %s: %s, diff: %f\n", jodisItems[0], jodisItems[1], redisItems[0], redisItems[1], diff);
//            }
//
//            jodisReader.close();
//            redisReader.close();




//            int code = ByteBuffer.wrap(bs).order(ByteOrder.LITTLE_ENDIAN).getInt();
//            System.out.println(code);
//            IntBuffer bb = ByteBuffer.wrap(bs).order(ByteOrder.nativeOrder()).asIntBuffer();
//            for (int i=0;i<bb.limit();i++) {
//                System.out.println(bb.get());
//        Element item = new Element(1.0, "AAA");
//        ConcurrentSkipListMap<String, Element> map = new ConcurrentSkipListMap<>();
//        map.put(item.member, item);
//        for (Map.Entry<String, Element> entry : map.entrySet()) {
//            Element val = entry.getValue();
//            val.score *= 10;
//        }
//
//        for (Map.Entry<String, Element> entry : map.entrySet()) {
//            Element val = entry.getValue();
//            System.out.printf("%s: %f\n", val.member, val.score);
//        }


//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }

//        long ret = CRC.calculateCRC(CRC.Parameters.CRC64ISO, "hello world".getBytes(StandardCharsets.UTF_8));
//        System.out.println(ret);

    }


//    public static void printRdbFile(File file) throws Exception {
//        try (RdbParser parser = new RdbParser(file)) {
//            Entry e;
//            while ((e = parser.readNext()) != null) {
//                switch (e.getType()) {
//
//                    case SELECT_DB:
//                        System.out.println("Processing DB: " + ((SelectDb)e).getId());
//                        System.out.println("------------");
//                        break;
//
//                    case EOF:
//                        System.out.print("End of file. Checksum: ");
//                        for (byte b : ((Eof)e).getChecksum()) {
//                            System.out.print(String.format("%02x", b & 0xff));
//                        }
//                        System.out.println();
//                        System.out.println("------------");
//                        break;
//
//                    case KEY_VALUE_PAIR:
//                        System.out.println("Key value pair");
//                        KeyValuePair kvp = (KeyValuePair)e;
//                        System.out.println("Key: " + new String(kvp.getKey(), StandardCharsets.US_ASCII));
//                        Long expireTime = kvp.getExpireTime();
//                        if (expireTime != null) {
//                            System.out.println("Expire time (ms): " + expireTime);
//                        }
//                        System.out.println("Value type: " + kvp.getValueType());
//                        System.out.print("Values: ");
//                        for (byte[] val : kvp.getValues()) {
//                            System.out.print(new String(val, StandardCharsets.US_ASCII) + " ");
//                        }
//                        System.out.println();
//                        System.out.println("------------");
//                        break;
//                }
//            }
//        }
//    }

    public static byte[] longToBytes(long data) {
        byte[] res = new byte[8];
        for(int i = 0; i < res.length; i++) {
            res[i] = (byte)(data >> 8*i);
        }
        return res;
    }



    public static void test(byte[] bs) {
        bs[0] = 'Z';
    }
}
